package com.shandong.controller;

import com.shandong.model.response.Oauth2UserinfoResult;
import com.shandong.service.IOauth2BasicUserService;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试接口
 *
 * @author wonangqi
 */
@RestController
public class TestController {

    @Resource
    private IOauth2BasicUserService basicUserService;

    @GetMapping("/test01")
//    @PreAuthorize("hasAuthority('SCOPE_message.read')")
    public String test01() {

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        System.out.println(authentication.getPrincipal());
        Oauth2UserinfoResult loginUserInfo = basicUserService.getLoginUserInfo();
        return loginUserInfo.toString();
    }

    @GetMapping("/test02")
    @PreAuthorize("hasAuthority('SCOPE_message.write')")
    public String test02() {
        return "test02";
    }

    @GetMapping("/app")
    @PreAuthorize("hasAuthority('app')")
    public String app() {
        return "app";
    }

    @GetMapping("/test03")
    public String test03() {
        return "test03";
    }

}